<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dbwork extends CI_Model{
    var $users_session_life = 60*60*24; // 1day
    function Dbwork(){
        parent::__construct();
        $this->load->database(); // вызываем, если database не указана в autoload
    }
    
    function get_session($login){
        $sql = "SELECT id FROM users WHERE users.login = ?";
        $query = $this->db->query($sql, array($login)); 
        
        if ($query->num_rows() > 0)
        {
           $row = $query->row_array();
           if( is_int($row['id']) ){
                $sql = "SELECT * FROM users_session WHERE users_session.id_users = ?";
                $query = $this->db->query($sql, array($row['id'])); 
                if($query->num_rows() == 0){
                    return FALSE;
                }
                elseif ($query->num_rows() == 1) {
                    $row = $query->row_array();
                    return $row['session'];
                }
                else{
                    $ar;
                    foreach ($query->result_array() as $row)
                    {
                      $ar[] = $row['session'];
                    }
                    return $ar;
                }
           }
        } 
    }
    function _del_session($id){
        //time
    }
}